package com.itheima.service.db.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.SmsCouponHistory;
import com.itheima.mapper.SmsCouponHistoryMapper;
import com.itheima.service.db.SmsCouponHistoryService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class SmsCouponHistoryServiceImpl implements SmsCouponHistoryService {

    @Autowired
    SmsCouponHistoryMapper smsCouponHistoryMapper;

    @Override
    public PageBeanVo findByPage(Integer pageNum, Integer pageSize, Long couponId,String orderSn,Integer useStatus) {
        Page<SmsCouponHistory> page = new Page<>(pageNum,pageSize);

        LambdaQueryWrapper<SmsCouponHistory> qw = new LambdaQueryWrapper<>();

        qw.eq(couponId!=null,SmsCouponHistory::getCouponId,couponId);
        qw.like(StrUtil.isNotEmpty(orderSn),SmsCouponHistory::getOrderSn,orderSn);
        qw.eq(useStatus!=null,SmsCouponHistory::getUseStatus,useStatus);

        Page<SmsCouponHistory> smsCouponHistoryPage = smsCouponHistoryMapper.selectPage(page, qw);

        return new PageBeanVo(pageNum,pageSize,smsCouponHistoryPage.getTotal(),smsCouponHistoryPage.getRecords());
    }
}
